﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display {
    import flash.events.*;
    import flash.display.*;
    import Engine.Helpers.*;
    import Classes.*;
    import Transactions.*;
    import Classes.util.*;

    public class StadiumDialog extends SWFDialog {

        public static const PROGRESSBAR_LEVEL_UP:String = "progressBarLevelUp";

        public var TRAINING_ENERGY_COST:int;
        private var m_close:GenericButton;
        private var m_training:GenericButton;
        private var m_challenge:GenericButton;
        private var m_trainOffense:GenericButton;
        private var m_trainDefense:GenericButton;
        private var m_defenseProgressBar:GenericProgressBar;
        private var m_offenseProgressBar:GenericProgressBar;
        private var m_pos:Vector2;
        private var m_stadium:Stadium;
        private var m_dialog:MovieClip;
        private var easyChallenge:GenericButton;
        private var evenChallenge:GenericButton;
        private var hardChallenge:GenericButton;
        private var challengePlayer:GenericButton;
        private var closeChallenge:GenericButton;

        public function StadiumDialog(_arg1:Stadium, _arg2:String, _arg3:Boolean=true){
            this.m_pos = new Vector2();
            this.m_stadium = _arg1;
            m_centered = true;
            m_dialogAsset = "assets/dialogs/StadiumDialog.swf";
            this.TRAINING_ENERGY_COST = Global.gameSettings.getAttribute("stadiumTrainingEnergyCost");
            addEventListener(PROGRESSBAR_LEVEL_UP, this.onProgressBarLevelUp);
            super(_arg3);
        }
        override protected function onLoadComplete():void{
            this.m_dialog = (m_loader.content as MovieClip);
            this.m_close = new GenericButton(this.m_dialog.mc.close_btn, this.onCloseClick);
            this.m_training = new GenericButton(this.m_dialog.mc.training_btn, this.onTrainingClick);
            this.m_challenge = new GenericButton(this.m_dialog.mc.challenge_btn, this.onChallengeClick);
            this.m_trainOffense = new GenericButton(this.m_dialog.mc.training_mc.trainOffense_btn, this.onTrainOffense);
            this.m_trainDefense = new GenericButton(this.m_dialog.mc.training_mc.trainDefense_btn, this.onTrainDefense);
            this.m_defenseProgressBar = new GenericProgressBar(this.m_dialog.mc.training_mc.defenseProgressBar, this);
            this.m_offenseProgressBar = new GenericProgressBar(this.m_dialog.mc.training_mc.offenseProgressBar, this);
            this.easyChallenge = new GenericButton(this.m_dialog.mc.challenge_mc.easy_challenge, this.onChallengePlayer);
            this.evenChallenge = new GenericButton(this.m_dialog.mc.challenge_mc.even_challenge, this.onChallengePlayer);
            this.hardChallenge = new GenericButton(this.m_dialog.mc.challenge_mc.hard_challenge, this.onChallengePlayer);
            this.challengePlayer = new GenericButton(this.m_dialog.mc.challengeWindow_mc.challenge_btn, this.onChallenge);
            this.closeChallenge = new GenericButton(this.m_dialog.mc.challengeWindow_mc.close_btn, this.onChallengeClose);
            this.m_dialog.mc.challengeWindow_mc.visible = false;
            this.m_defenseProgressBar.setPercentage(this.m_stadium.defensePercentage);
            this.m_defenseProgressBar.eventType = PROGRESSBAR_LEVEL_UP;
            this.m_offenseProgressBar.setPercentage(this.m_stadium.offensePercentage);
            this.m_offenseProgressBar.eventType = PROGRESSBAR_LEVEL_UP;
            this.m_dialog.mc.challenge_mc.visible = false;
            this.m_dialog.mc.training_btn_shadow.visible = false;
            this.m_dialog.mc.name_label.text = this.getPlayerName();
            this.m_dialog.mc.stadium_label.text = this.getStadiumName();
            this.m_dialog.mc.training_mc.offenseLvl_label.text = this.m_stadium.offenseLvl;
            this.m_dialog.mc.training_mc.defenseLvl_label.text = this.m_stadium.defenseLvl;
            addChild(this.m_dialog);
        }
        private function onCloseClick(_arg1:MouseEvent):void{
            close();
            var _local2:Event = new Event(Event.CLOSE);
            this.dispatchEvent(_local2);
            this.removeEventListener(PROGRESSBAR_LEVEL_UP, this.onProgressBarLevelUp);
            this.m_close = null;
            this.m_training = null;
            this.m_challenge = null;
            this.m_trainOffense = null;
            this.m_trainDefense = null;
            this.m_defenseProgressBar;
            this.m_offenseProgressBar;
            this.easyChallenge = null;
            this.evenChallenge = null;
            this.hardChallenge = null;
            this.challengePlayer = null;
            this.closeChallenge = null;
        }
        private function onTrainingClick(_arg1:MouseEvent):void{
            this.m_dialog.mc.challenge_mc.visible = false;
            this.m_dialog.mc.training_mc.visible = true;
            this.m_dialog.mc.training_btn_shadow.visible = false;
            this.m_dialog.mc.challenge_btn_shadow.visible = true;
        }
        private function onChallengeClick(_arg1:MouseEvent):void{
            this.m_dialog.mc.challenge_mc.visible = true;
            this.m_dialog.mc.training_mc.visible = false;
            this.m_dialog.mc.training_btn_shadow.visible = true;
            this.m_dialog.mc.challenge_btn_shadow.visible = false;
        }
        private function onTrainOffense(_arg1:MouseEvent):void{
            if (Global.player.energy >= this.TRAINING_ENERGY_COST){
                Global.player.updateEnergy(-(this.TRAINING_ENERGY_COST), new Array("energy", "expenditures", "stadium", ""));
                this.m_stadium.trainOffense();
                this.m_dialog.mc.training_mc.offenseTrain_cost.gotoAndPlay(1);
                this.m_offenseProgressBar.setPercentage(this.m_stadium.offensePercentage);
            };
        }
        private function onTrainDefense(_arg1:MouseEvent):void{
            if (Global.player.energy >= this.TRAINING_ENERGY_COST){
                Global.player.updateEnergy(-(this.TRAINING_ENERGY_COST), new Array("energy", "expenditures", "stadium", ""));
                this.m_stadium.trainDefense();
                this.m_dialog.mc.training_mc.defenseTrain_cost.gotoAndPlay(1);
                this.m_defenseProgressBar.setPercentage(this.m_stadium.defensePercentage);
            };
        }
        private function getPlayerName():String{
            var _local1:String = Global.getPlayer().name;
            _local1 = _local1.slice(0, _local1.indexOf(" "));
            _local1 = (_local1 + ZLoc.t("Main", "TeamLabel"));
            return (_local1);
        }
        private function getStadiumName():String{
            switch (this.m_stadium.stadiumType){
                case Stadium.SOCCER_STADIUM:
                    return (this.m_stadium.getItem().localizedName);
                case Stadium.BASEBALL_STADIUM:
                    return (this.m_stadium.getItem().localizedName);
            };
            return (ZLoc.t("Main", "StadiumNameDefault"));
        }
        private function onProgressBarLevelUp(_arg1:Event):void{
            this.m_dialog.mc.training_mc.offenseLvl_label.text = this.m_stadium.offenseLvl;
            this.m_dialog.mc.training_mc.defenseLvl_label.text = this.m_stadium.defenseLvl;
        }
        private function onChallenge(_arg1:MouseEvent):void{
            GameTransactionManager.addTransaction(new TStadiumChallenge(this.m_stadium, this.m_stadium.stats), true);
            _arg1 = new MouseEvent(MouseEvent.CLICK);
            this.onCloseClick(_arg1);
        }
        private function onChallengePlayer(_arg1:MouseEvent):void{
            this.m_dialog.mc.challenge_mc.visible = false;
            this.m_dialog.mc.training_mc.visible = false;
            this.m_dialog.mc.challengeWindow_mc.visible = true;
        }
        private function onChallengeClose(_arg1:MouseEvent):void{
            this.m_dialog.mc.challenge_mc.visible = true;
            this.m_dialog.mc.training_mc.visible = false;
            this.m_dialog.mc.challengeWindow_mc.visible = false;
        }

    }
}//package Display 
